//
//  BNMainViewController.m
//  BeautifulNote
//
//  Created by Apple on 2019/7/19.
//  Copyright © 2019 Maker. All rights reserved.
//

#import "BNMainViewController.h"
#import "BNHomeController.h"
#import "BNMakeController.h"

@interface BNMainViewController ()

@property (nonatomic, strong) UIButton *firstButton;
@property (nonatomic, strong) UIButton *thridButton;
@property (nonatomic, strong) UIView *topView;
@property (nonatomic, strong) UIView *line_first;
@property (nonatomic, strong) UIView *line_second;
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) BNHomeController *firstVC;
@property (nonatomic, strong) BNMakeController *thridVC;


@end

@implementation BNMainViewController

#pragma mark - life cycle

- (void)viewDidLoad {
    [super viewDidLoad];

    [self initControllers];
    [self addSubViews];
}


#pragma mark - [系统控件的<#Class#>Protocol]

#pragma mark - [自定义控件的<#Class#> Protocol]

#pragma mark - [core相关的<#Class#>Protocol]

#pragma mark - event response
- (void)clickTopButotn:(UIButton *)button {
    [UIView animateWithDuration:0.25 animations:^{
        self.scrollView.contentOffset = CGPointMake(ScreenWidth * button.tag, 0);
    }];
}

#pragma mark - public methods

#pragma mark - private methods
- (void)addSubViews {
    
    CGFloat buttonWidth = 40;
    
    CGFloat top = SafeAreaTopHeight + StatusBarHeight + 15;
    
    [self.view addSubview:self.topView];
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(top);
        make.centerX.mas_equalTo(0);
        make.width.mas_equalTo(buttonWidth * 4);
        make.height.mas_equalTo(buttonWidth);
    }];
    
    [self.topView addSubview:self.firstButton];
    [self.firstButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_equalTo(0);
        make.width.mas_equalTo(buttonWidth * 2);
        make.height.mas_equalTo(buttonWidth);
    }];
    
    [self.topView addSubview:self.thridButton];
    [self.thridButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(buttonWidth * 2);
        make.top.mas_equalTo(0);
        make.width.mas_equalTo(buttonWidth * 2);
        make.height.mas_equalTo(buttonWidth);
    }];
    
    [self.topView addSubview:self.line_first];
    [self.line_first mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(buttonWidth * 2);
        make.bottom.top.mas_equalTo(0);
        make.width.mas_equalTo(1);
    }];
    
    [self.topView addSubview:self.line_second];
    [self.line_second mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(buttonWidth * 4);
        make.bottom.top.mas_equalTo(0);
        make.width.mas_equalTo(1);
    }];
    
    
    CGFloat scrollH = ScreenHeight - (top + buttonWidth + 10);
    
    [self.view addSubview:self.scrollView];
    self.scrollView.frame = CGRectMake(0, top + buttonWidth + 10, ScreenWidth, scrollH);
    
    [self.scrollView addSubview:self.firstVC.view];
    self.firstVC.view.frame = CGRectMake(0, 0, ScreenWidth, scrollH);
    
    [self.scrollView addSubview:self.thridVC.view];
    self.thridVC.view.frame = CGRectMake(ScreenWidth, 0, ScreenWidth, scrollH);
    
    self.scrollView.contentSize = CGSizeMake(ScreenWidth * 2, scrollH);

}

- (void)initControllers {
    
    self.view.backgroundColor = mainColor;
    
    self.firstVC = [BNHomeController new];
    [self addChildViewController:self.firstVC];
    
    self.thridVC = [BNMakeController new];
    [self addChildViewController:self.thridVC];
}
#pragma mark - getters and setters
- (UIButton *)firstButton {
    if (!_firstButton) {
        _firstButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_firstButton setImage:[UIImage imageNamed:@"I"] forState:UIControlStateNormal];
        _firstButton.showsTouchWhenHighlighted = YES;
        _firstButton.tag = 0;
        [_firstButton addTarget:self action:@selector(clickTopButotn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _firstButton;
}

- (UIButton *)thridButton {
    if (!_thridButton) {
        _thridButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_thridButton setImage:[UIImage imageNamed:@"you"] forState:UIControlStateNormal];
        _thridButton.showsTouchWhenHighlighted = YES;
        _thridButton.tag = 1;
        [_thridButton addTarget:self action:@selector(clickTopButotn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _thridButton;
}

- (UIScrollView *)scrollView {
    if (!_scrollView) {
        _scrollView = [UIScrollView new];
        _scrollView.pagingEnabled = YES;
        _scrollView.showsHorizontalScrollIndicator = NO;
    }
    return _scrollView;
}

- (UIView *)topView {
    if (!_topView) {
        _topView = [UIView new];
        _topView.layer.cornerRadius = 4;
        _topView.layer.masksToBounds = YES;
        _topView.layer.borderColor = bnColor(237, 237, 237).CGColor;
        _topView.layer.borderWidth = 1.0f;
    }
    return _topView;
}

- (UIView *)line_first {
    if (!_line_first) {
        _line_first = [UIView new];
        _line_first.backgroundColor = bnColor(237, 237, 237);
    }
    return _line_first;
}

- (UIView *)line_second {
    if (!_line_second) {
        _line_second = [UIView new];
        _line_second.backgroundColor = bnColor(237, 237, 237);
    }
    return _line_second;
}
@end
